//
//  JSScrollViewController.m
//  无限滚动
//
//  Created by Liekkas on 16/3/21.
//  Copyright © 2016年 Admin. All rights reserved.
//

#import "JSScrollViewController.h"
#import "JSScrollCell.h"
#import "JSScroll.h"

@interface JSScrollViewController () <UICollectionViewDataSource>

@property (nonatomic, strong) NSMutableArray *itemArray;

@property (nonatomic, strong) UICollectionView *collectionView;

@end

@implementation JSScrollViewController

static NSString *ID = @"cell";

- (NSMutableArray *)itemArray
{
    if (!_itemArray) {
        _itemArray = [NSMutableArray array];
    }
    return _itemArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
   //设置图片
    [self setUPImage];
    
    [self.collectionView registerClass:[JSScrollCell class] forCellWithReuseIdentifier:ID];
    
    
    
}

- (void)setUPImage
{
    
    //创建uiview
    UIImageView *imageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img_01"]];
    
    [self.itemArray addObject:imageV];
    
    JSScroll *scroll = [[JSScroll alloc] init];
    
    scroll.scrollV = imageV;
    
    [self.itemArray addObject:imageV];
    
    [self.collectionView addSubview:imageV];
    
//    //设置图片
//    JSScroll *item = [[JSScroll alloc] init];
//    
//    NSInteger count = 5;
//   
//    
//    
//    for (NSInteger i = 0; i < count; i++) {
//    
//    NSString *imageStr = [NSString stringWithFormat:@"img_0%ld", i + 1];
//        
//        NSLog(@"%@", imageStr);
//    
//    //UIImageView *imageV = [[UIImageView alloc] init];
//    
//        UIImage *image = [UIImage imageNamed:imageStr];
//    item.scrollPicture = image;
//        
//    
//    //NSLog(@"%@", item.scrollPicture);
//        
//    
//    [self.itemArray addObject:item];
//    
    
    
    
        
        
        //[self.view addSubview:image];
    
    //[view addSubview:imageV];
    
    //item.scrollPicture = imageV;

}

- (instancetype)init
{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    
    //flowLayout.itemSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 150);
    
    flowLayout.minimumLineSpacing = 0;
    
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    return [super initWithCollectionViewLayout:flowLayout];
}


#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
#warning Incomplete implementation, return the number of sections
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of items
    NSLog(@"%ld", self.itemArray.count);

    return 20;
    
    }

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    JSScrollCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
    
    JSScroll *scroll = self.itemArray[indexPath.item];
    
    cell.scroll = scroll;
    
    return cell;
}


@end
